//
//  HMSearchViewController.m
//  HMMeituanHD
//
//  Created by apple on 2017/5/22.
//  Copyright © 2017年 itheima. All rights reserved.
//

#import "HMSearchViewController.h"

@interface HMSearchViewController ()<UISearchBarDelegate, HMRequestParam>
//搜索框
@property (nonatomic, weak) UISearchBar *searchBar;

@end

@implementation HMSearchViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //设置导航栏
    [self setupNav];
}

//设置导航栏
- (void)setupNav{

    //添加返回Item
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barBuutonItemWithTarget:self action:@selector(clickBackItem) icon:@"icon_back" highlighticon:@"icon_back_highlighted"];
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    //设置代理  监听搜索框内容变化
    searchBar.delegate = self;
    //设置占位内容
    searchBar.placeholder = @"请输入搜索的内容";
    self.navigationItem.titleView = searchBar;
    self.searchBar = searchBar;
}


- (void)clickBackItem{

    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UISearchBarDelegate

//当搜索框内容发生变化后调用
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{

    //执行下拉刷新,请求数据
    [self.collectionView.mj_header beginRefreshing];
}


#pragma mark - HMRequestParam

- (HMRequestType)addCustemParam:(NSMutableDictionary *)baseParam{

    if (self.searchBar.text.length) {
        
        //设置自定义参数
        [baseParam setValue:self.searchBar.text forKey:@"keyword"];
        //设置返回值
        return HMRequestTypeNetwork;
        
    }else {
    
        return HMRequestTypeClearUI;
    }
}


@end
